home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Resources / Burning & Media / GB-PVR 1.2.13 / GBPVR10213.msi / Cabs.w1.cab / SearchResults2.aspx.cs584 < prev    next >
Text File  |  2008-04-02  |  45KB  |  887 lines

  1. using System;
  2. using System.Collections;
  3. using System.Collections.Specialized;
  4. using System.Data.Common;
  5. using System.IO;
  6. using System.Web.UI;
  7. using System.Web.UI.HtmlControls;
  8. using System.Web.UI.WebControls;
  9. using System.Web;
  10. using System.Xml;
  11. using GBPVR.Public;
  12. using GBPVRSchedule;
  13. using gbweb.classes;
  14.  
  15. namespace gbweb
  16. {
  17.     /// <summary>
  18.     /// Summary description for SearchResults.
  19.     /// </summary>
  20.     public partial class SearchResults2 : System.Web.UI.Page
  21.     {
  22.         protected System.Web.UI.WebControls.DropDownList DropDownList1;
  23.         protected Settings guideParams;
  24.         protected ProgramTreeItem[] pgmTree;
  25.         protected int treeIdx;
  26.  
  27.         private string sortOrder = string.Empty;
  28.         private ArrayList sortOrders;
  29.         private ArrayList displayProgrammeSort = new ArrayList();
  30.  
  31.         Hashtable channelCache = new Hashtable();
  32.  
  33.         protected void Page_Load(object sender, System.EventArgs e)
  34.         {
  35.             treeIdx = 0;
  36.             pgmTree = new ProgramTreeItem[10000];
  37.  
  38.             guideParams = Global.Settings;
  39.  
  40.             HttpCookie cookie = Request.Cookies["showSearchResults"];
  41.  
  42.             //Clear out the listings area so that you don't get leftovers from the previous display
  43.             CONTENTS.InnerHtml = "";
  44.  
  45.             //Remove a programme if someone clicked on Cancel prior t loading the list of programmes so that it is gone and does not appear again
  46.             string cancel = null;
  47.             cancel = Request.Params["cancel"];
  48.             if ((cancel != null) && (cancel.Length > 0))
  49.             {
  50.                 Schedule scheduleHelper = Global.Schedule;
  51.                 ScheduledRecording scheduledRecording = scheduleHelper.GetScheduledRecordingByOID(Convert.ToInt32(cancel));
  52.                 if (scheduledRecording != null)
  53.                 {
  54.                     scheduleHelper.CancelScheduledRecording(scheduledRecording);
  55.                 }
  56.             }
  57.  
  58.             //Only execute on the first page load
  59.             if (!IsPostBack)
  60.             {
  61.                 //Set the Day/date/time display on the header
  62.                 viewDate.InnerText = DateTime.Now.ToLongDateString().Trim();
  63.                 serverTime.InnerText = "Server Time: " + DateTime.Now.ToLongTimeString().Trim();
  64.  
  65.                 //Set the header tab of the Search to active
  66.                 NAV_SEARCH.Attributes.Add("class", "currentTab");
  67.                 NAV_RECORDINGS.Visible = guideParams.showManage;
  68.                 NAV_SEARCH.Visible = guideParams.showSearch;
  69.                 NAV_VIDEO.Visible = guideParams.showVideoLib;
  70.                 NAV_MUSIC.Visible = guideParams.showMusicLib;
  71.                 NAV_PHOTO.Visible = guideParams.showPhotoLib;
  72.                 NAV_STATS.Visible = guideParams.showStats;
  73.  
  74.                 //If the user has opted to use the TreeView search results allow the user to see the sort order
  75.                 //options otherwise do not show them
  76.  
  77.                 XmlNode pre = Global.Config.SelectSingleNode("/settings/PreShowPadding");
  78.                 XmlNode post = Global.Config.SelectSingleNode("/settings/PostShowPadding");
  79.                 prePadding.Text = pre.InnerText;
  80.                 postPadding.Text = post.InnerText;
  81.  
  82.                 sr_searchResults.SelectedValue = cookie != null ? cookie.Value : "table";
  83.  
  84.                 if (sr_searchResults.SelectedValue == "tree")
  85.                 {
  86.                     treeControl.Visible = true;
  87.                     sortResults.Visible = true;
  88.                     sortResults2.Visible = true;
  89.                     
  90.                     //If the user has ExtendedEWA then dynamicaly add a button for Star Rating sort
  91.                     if (ExtendedEWA.Initialize())
  92.                     {
  93.                         ListItem starRating = new ListItem();
  94.                         starRating.Text = "Star Rating";
  95.                         starRating.Value = "star";
  96.                         srtOrder.Items.Add(starRating);
  97.  
  98.                         ListItem originalAirDate = new ListItem();
  99.                         originalAirDate.Text = "Original Air Date (oad)";
  100.                         originalAirDate.Value = "originalAirDate";
  101.                         srtOrder.Items.Add(originalAirDate);
  102.                     }
  103.  
  104.                     //Set the selected search order to whatever was used on the search criteria page
  105.                     string treeSortOrder = Convert.ToString(Session["SearchResultsOption"]);
  106.                     if (treeSortOrder != null)
  107.                     {
  108.                         srtOrder.SelectedValue = sortOrder;
  109.                     }
  110.                     else
  111.                     {
  112.                         cookie = Request.Cookies["SearchSortOrder"];
  113.                         srtOrder.SelectedValue = cookie != null ? cookie.Value : "title";
  114.                     }
  115.                     //Store the selected display (table or tree) in the cookie for the next search
  116.                     cookie = new HttpCookie("showSearchResults", sr_searchResults.SelectedValue);
  117.                     cookie.Expires = DateTime.Now.AddYears(1);
  118.                     Response.Cookies.Add(cookie);
  119.                 }
  120.                 else
  121.                 {
  122.                     treeControl.Visible = false;
  123.                     sortResults.Visible = false;
  124.                     sortResults2.Visible = false;
  125.                 }
  126.  
  127.                 if ((Request.Params["checkTitle"] != null) || (Request.Params["checkDescription"] != null) || (Request.Params["checkSubtitle"] != null) || (Request.Params["listChannels"] != null) ||
  128.                     (Request.Params["matchTitle"] != null) || (Request.Params["matchDesc"] != null) || (Request.Params["matchSubtitle"] != null) || (Request.Params["matchUniqueID"] != null) ||
  129.                     (Request.Params["textMinLength"] != null) && (Request.Params["textMinLength"].Length > 0) ||
  130.                     ((Request.Params["textMaxLength"] != null) && (Request.Params["textMaxLength"].Length > 0)) ||
  131.                     Request.Params["startDate"] != null || Request.Params["startTime"] != null ||
  132.                     Request.Params["endDate"] != null || Request.Params["endTime"] != null)
  133.                 {
  134.                     int minLength = int.MinValue;
  135.                     int maxLength = int.MaxValue;
  136.                     Session["startDate"] = "01/01/1901";
  137.                     Session["startTime"] = "01:01 AM";
  138.  
  139.                     Session["endDate"] = "01/01/1901";
  140.                     Session["endTime"] = "01:01 AM";
  141.  
  142.                     if ((Request.Params["textMinLength"] != null) && (Request.Params["textMinLength"].Length > 0)) minLength = int.Parse(Request.Params["textMinLength"]);
  143.                     if ((Request.Params["textMaxLength"] != null) && (Request.Params["textMaxLength"].Length > 0)) maxLength = int.Parse(Request.Params["textMaxLength"]);
  144.  
  145.                     if ((Request.Params["startDate:textBox"] != null) && (Request.Params["startDate:textBox"].Length > 0))
  146.                     {
  147.                         Session["startDate"] = Request.Params["startDate:textBox"];
  148.                     }
  149.  
  150.                     if ((Request.Params["startTime:textBox"] != null) && (Request.Params["startTime:textBox"].Length > 0))
  151.                     {
  152.                         Session["startTime"] = Request.Params["startTime:textBox"];
  153.                     }
  154.  
  155.                     if ((Request.Params["endDate:textBox"] != null) && (Request.Params["endDate:textBox"].Length > 0))
  156.                     {
  157.                         Session["endDate"] = Request.Params["endDate:textBox"];
  158.                     }
  159.  
  160.                     if ((Request.Params["endTime:textBox"] != null) && (Request.Params["endTime:textBox"].Length > 0))
  161.                     {
  162.                         Session["endTime"] = Request.Params["endTime:textBox"];
  163.                     }
  164.  
  165.                     string[] channels = new string[0] { };
  166.                     if (Request.Params["listChannels"] != null) channels = Request.Params["listChannels"].Split(',');
  167.  
  168.                     string[] genres = new string[0] { };
  169.                     if (Request.Params["genreList"] != null) genres = Request.Params["genreList"].Split(',');
  170.  
  171.                     Session["checkTitle"] = Request.Params["checkTitle"] != null;
  172.  
  173.                     Session["checkDescription"] = Request.Params["checkDescription"] != null;
  174.  
  175.                     Session["checkSubtitle"] = Request.Params["checkSubtitle"] != null;
  176.  
  177.                     Session["matchTitle"] = Request.Params["matchTitle"] != null;
  178.  
  179.                     Session["matchDesc"] = Request.Params["matchDesc"] != null;
  180.  
  181.                     Session["matchSubtitle"] = Request.Params["matchSubtitle"] != null;
  182.  
  183.                     Session["matchUniqueID"] = Request.Params["matchUniqueID"] != null;
  184.  
  185.                     Session["textKeyWord"] = Request.Params["searchPhrase"];
  186.  
  187.                     Session["caseSensitive"] = Request.Params["caseSensitive"] != null;
  188.  
  189.                     Session["genreList"] = genres;
  190.  
  191.                     Session["minLength"] = minLength;
  192.  
  193.                     Session["maxLength"] = maxLength;
  194.  
  195.                     Session["channels"] = channels;
  196.  
  197.                     //Set the default recording Quality
  198.                     quality.SelectedValue = Global.Settings.recordingQuality;
  199.                 }
  200.                 else
  201.                 {
  202.                     if (Request["sort"] == null)
  203.                     {
  204.                         Response.Redirect("Search2.aspx");
  205.                     }
  206.                 }
  207.             }
  208.             else
  209.             {
  210.                 if (sr_searchResults.SelectedValue == "tree")
  211.                 {
  212.                     treeControl.Visible = true;
  213.                     sortResults.Visible = true;
  214.                     sortResults2.Visible = true;
  215.                 }
  216.                 else
  217.                 {
  218.                     treeControl.Visible = false;
  219.                     sortResults.Visible = false;
  220.                     sortResults2.Visible = false;
  221.                 }
  222.             }
  223.  
  224.  
  225.             //Store the selected sort order in the cookie for the next search
  226.             cookie = new HttpCookie("SearchSortOrder", srtOrder.SelectedValue);
  227.             cookie.Expires = DateTime.Now.AddYears(1);
  228.             Response.Cookies.Add(cookie);
  229.  
  230.             //Store the selected display (table or tree) in the cookie for the next search
  231.             //
  232.             cookie = new HttpCookie("showSearchResults", sr_searchResults.SelectedValue);
  233.             cookie.Expires = DateTime.Now.AddYears(1);
  234.             Response.Cookies.Add(cookie);
  235.  
  236.             //Read the cookie for the sort order of the display
  237.             cookie = Request.Cookies["sortOrderSearch"];
  238.             sortOrder = cookie != null ? cookie.Value.Trim(',') : "datetime,channel,title,status";
  239.             sortOrders = new ArrayList(sortOrder.Split(','));
  240.             string newSort = Request["sort"];
  241.             if (newSort != null)
  242.             {
  243.                 if (sortOrders.Contains(newSort))
  244.                 {
  245.                     if (sortOrders[0].ToString() == newSort)
  246.                     {
  247.                         sortOrders.Remove(newSort);
  248.                         sortOrders.Insert(0, newSort + " desc");
  249.                     }
  250.                     else
  251.                     {
  252.                         sortOrders.Remove(newSort);
  253.                         sortOrders.Insert(0, newSort);
  254.                     }
  255.                 }
  256.                 else
  257.                 {
  258.                     sortOrders.Remove(newSort + " desc");
  259.                     sortOrders.Insert(0, newSort);
  260.                 }
  261.             }
  262.             sortOrder = string.Join(",", (string[])sortOrders.ToArray(typeof(string)));
  263.  
  264.             //Update the sort settings in the cookie for the next display
  265.             cookie = new HttpCookie("sortOrderSearch", sortOrder);
  266.             cookie.Expires = DateTime.Now.AddYears(1);
  267.             Response.Cookies.Add(cookie);
  268.  
  269.             processViews();
  270.  
  271.         }
  272.  
  273.         #region Page Load code for common processing of views - processViews
  274.         private void processViews()
  275.         {
  276.             //Turn on the appropriate display elements while turning off the one not being used
  277.             if (sr_searchResults.SelectedValue == "table")
  278.             {
  279.                 RECORDINGS_HEADER.Visible = true;
  280.                 SORT_HEADER.Visible = false;
  281.             }
  282.             else
  283.             {
  284.                 forcedScrollbar.InnerHtml = "";
  285.                 SORT_HEADER.Visible = true;
  286.                 RECORDINGS_HEADER.Visible = false;
  287.             }
  288.         }
  289.  
  290.         #endregion
  291.  
  292.         protected void SearchResults_PreRender(object sender, System.EventArgs e)
  293.         {
  294.             SearchForEpisode(
  295.                 (bool)Session["checkTitle"],
  296.                 (bool)Session["checkDescription"],
  297.                 (bool)Session["checkSubtitle"],
  298.                 (bool)Session["matchTitle"],
  299.                 (bool)Session["matchDesc"],
  300.                 (bool)Session["matchSubtitle"],
  301.                 (bool)Session["matchUniqueID"],
  302.                 (string)Session["textKeyWord"],
  303.                 (bool)Session["caseSensitive"],
  304.                 (int)Session["minLength"],
  305.                 (int)Session["maxLength"],
  306.                 (string[])Session["channels"],
  307.                 (string[])Session["genreList"],
  308.                 (string)Session["startDate"],
  309.                 (string)Session["startTime"],
  310.                 (string)Session["endDate"],
  311.                 (string)Session["endTime"]);
  312.         }
  313.  
  314.         protected void hlRecord_Click(object sender, System.EventArgs e)
  315.         {
  316.             // schedule recordings
  317.             Schedule.Quality quality = 0;
  318.             switch (Request.Params["quality"].ToLower())
  319.             {
  320.                 case "high":
  321.                     quality = Schedule.Quality.High;
  322.                     break;
  323.  
  324.                 case "medium":
  325.                     quality = Schedule.Quality.Medium;
  326.                     break;
  327.  
  328.                 case "low":
  329.                     quality = Schedule.Quality.Low;
  330.                     break;
  331.  
  332.                 case "custom1":
  333.                     quality = Schedule.Quality.Custom1;
  334.                     break;
  335.  
  336.                 case "custom2":
  337.                     quality = Schedule.Quality.Custom2;
  338.                     break;
  339.             }
  340.  
  341.             Schedule scheduleHelper = Global.Schedule;
  342.             int prePad = Convert.ToInt32(prePadding.Text);
  343.             int postPad = Convert.ToInt32(postPadding.Text);
  344.             if (radioTime.SelectedValue == "once")
  345.             {
  346.                 if (sr_searchResults.SelectedValue != "tree")
  347.                 {
  348.                     foreach (string param in Request.Params.Keys)
  349.                     {
  350.                         if (param.StartsWith("item"))
  351.                         {
  352.                             Programme programme = scheduleHelper.GetProgrammeByOID(int.Parse(param.Substring(4)));
  353.                             
  354.                             Schedule myschedule = Global.Schedule;
  355.  
  356.                             if (Convert.ToDouble(extendMinutes.Text) != 0)
  357.                             {
  358.                                 //Add the number of minutes that was entered to the end time of the recording to set the new end time
  359.                                 DateTime newEndDate =
  360.                                     programme.getEndTime().AddMinutes(Convert.ToDouble(extendMinutes.Text));
  361.                                 //Set the new end time for the recording
  362.                                 programme.setEndTime(newEndDate);
  363.                             }
  364.  
  365.                             bool scheduleReturn = myschedule.ScheduleOnce(programme, quality, prePad, postPad);
  366.                             Channel chnl = myschedule.GetChannelByOID(programme.getChannelOID());
  367.                             Recordings.Items.Add(programme.getOID().ToString() + "@" + chnl.channelName + " " + programme.getTitle().ToString() + " " + programme.getStartTime().ToLongDateString() + " " + programme.getStartTime().ToShortTimeString() + " - " + programme.getEndTime().ToShortTimeString());
  368.                         }
  369.                     }
  370.                 }
  371.                 else
  372.                 {
  373.                     foreach (TreeNode node in TreeView1.CheckedNodes)
  374.                     {
  375.                         Programme programme = scheduleHelper.GetProgrammeByOID(System.Convert.ToInt32(node.Value));
  376.                         Schedule myschedule = Global.Schedule;
  377.  
  378.                         if (Convert.ToDouble(extendMinutes.Text) != 0)
  379.                         {
  380.                             //Add the number of minutes that was entered to the end time of the recording to set the new end time
  381.                             DateTime newEndDate =
  382.                                 programme.getEndTime().AddMinutes(Convert.ToDouble(extendMinutes.Text));
  383.                             //Set the new end time for the recording
  384.                             programme.setEndTime(newEndDate);
  385.                         }
  386.  
  387.                         bool scheduleReturn = myschedule.ScheduleOnce(programme, quality, prePad, postPad);
  388.                         Channel chnl = myschedule.GetChannelByOID(programme.getChannelOID());
  389.                         Recordings.Items.Add(programme.getOID().ToString() + "@" + chnl.channelName + " " + programme.getTitle().ToString() + " " + programme.getStartTime().ToLongDateString() + " " + programme.getStartTime().ToShortTimeString() + " - " + programme.getEndTime().ToShortTimeString());
  390.                     }
  391.                 }
  392.             }
  393.             else
  394.             {
  395.                 HybridDictionary processedRecordings = new HybridDictionary();
  396.                 if (sr_searchResults.SelectedValue != "tree")
  397.                 {
  398.                     foreach (string param in Request.Params.Keys)
  399.                     {
  400.                         if (param.StartsWith("item"))
  401.                         {
  402.                             Programme programme = scheduleHelper.GetProgrammeByOID(int.Parse(param.Substring(4)));
  403.  
  404.                             if (Convert.ToDouble(extendMinutes.Text) != 0)
  405.                             {
  406.                                 //Add the number of minutes that was entered to the end time of the recording to set the new end time
  407.                                 DateTime newEndDate =
  408.                                     programme.getEndTime().AddMinutes(Convert.ToDouble(extendMinutes.Text));
  409.                                 //Set the new end time for the recording
  410.                                 programme.setEndTime(newEndDate);
  411.                             }
  412.  
  413.                             string uniqueProgrammeKey = programme.getChannelOID().ToString() + ":" + programme.getTitle();
  414.  
  415.                             if (!processedRecordings.Contains(uniqueProgrammeKey))
  416.                             {
  417.                                 //Set the max number of recordings to keep for the show
  418.                                 int keepnumRecordings = ReoccuringRecordingExtras.KEEP_ALL_FILES;
  419.                                 if (keepRecordings.Text.ToString() != null)
  420.                                 {
  421.                                     try
  422.                                     {
  423.                                         keepnumRecordings = Convert.ToInt32(keepRecordings.Text);
  424.                                     }
  425.                                     catch
  426.                                     {
  427.                                         keepnumRecordings = ReoccuringRecordingExtras.KEEP_ALL_FILES;
  428.                                     }
  429.                                 }
  430.                                 else
  431.                                 {
  432.                                     keepnumRecordings = ReoccuringRecordingExtras.KEEP_ALL_FILES;
  433.                                 }
  434.  
  435.                                 Schedule myschedule = Global.Schedule;
  436.  
  437.                                 if (radioTime.SelectedValue == "thisTime")
  438.                                 {
  439.                                     // schedule season recording for any day and this time
  440.                                     if (radioDay.SelectedValue == "anyDay")
  441.                                     {
  442.                                         bool scheduleReturn = myschedule.ScheduleThisTime(programme, quality, Schedule.DayType.SheduleAnyDay, keepnumRecordings, Schedule.RecType.Season, prePad, postPad);
  443.                                     }
  444.                                     // schedule season recording for only this day and this time
  445.                                     else if (radioDay.SelectedValue == "thisDay")
  446.                                     {
  447.                                         bool scheduleReturn = myschedule.ScheduleThisTime(programme, quality, Schedule.DayType.SheduleThisDay, keepnumRecordings, Schedule.RecType.Season, prePad, postPad);
  448.                                     }
  449.                                     // schedule season recording for the selected days and this time
  450.                                     else
  451.                                     {
  452.                                         ArrayList dayList = new ArrayList();
  453.                                         // Iterate through the Items collection of the checkedDays 
  454.                                         // control and create the correct number for the season recording.
  455.                                         if (checkedDays_0.Checked)
  456.                                         {
  457.                                             dayList.Add(Schedule.Day.Monday);
  458.                                         }
  459.                                         if (checkedDays_1.Checked)
  460.                                         {
  461.                                             dayList.Add(Schedule.Day.Tuesday);
  462.                                         }
  463.                                         if (checkedDays_2.Checked)
  464.                                         {
  465.                                             dayList.Add(Schedule.Day.Wednesday);
  466.                                         }
  467.                                         if (checkedDays_3.Checked)
  468.                                         {
  469.                                             dayList.Add(Schedule.Day.Thursday);
  470.                                         }
  471.                                         if (checkedDays_4.Checked)
  472.                                         {
  473.                                             dayList.Add(Schedule.Day.Friday);
  474.                                         }
  475.                                         if (checkedDays_5.Checked)
  476.                                         {
  477.                                             dayList.Add(Schedule.Day.Saturday);
  478.                                         }
  479.                                         if (checkedDays_6.Checked)
  480.                                         {
  481.                                             dayList.Add(Schedule.Day.Sunday);
  482.                                         }
  483.                                         bool scheduleReturn = myschedule.ScheduleThisTime(programme, quality, Schedule.DayType.SheduleSpecificDays, keepnumRecordings, dayList, Schedule.RecType.Season, prePad, postPad);
  484.                                     }
  485.                                 }
  486.                                 else
  487.                                 {
  488.                                     // schedule season recording for anyday anytime
  489.                                     if (radioDay.SelectedValue == "anyDay")
  490.                                     {
  491.                                         bool scheduleReturn = myschedule.ScheduleAnyTime(programme, quality, Schedule.DayType.SheduleAnyDay, keepnumRecordings, Schedule.RecType.Season, prePad, postPad);
  492.                                     }
  493.                                     // schedule season recording for only this day and thisany time
  494.                                     else if (radioDay.SelectedValue == "thisDay")
  495.                                     {
  496.                                         bool scheduleReturn = myschedule.ScheduleAnyTime(programme, quality, Schedule.DayType.SheduleThisDay, keepnumRecordings, Schedule.RecType.Season, prePad, postPad);
  497.                                     }
  498.                                     // schedule season recording for the selected days and this time
  499.                                     else
  500.                                     {
  501.                                         ArrayList dayList = new ArrayList();
  502.                                         // Iterate through the Items collection of the checkedDays 
  503.                                         // control and create the correct number for the season recording.
  504.                                         if (checkedDays_0.Checked)
  505.                                         {
  506.                                             dayList.Add(Schedule.Day.Monday);
  507.                                         }
  508.                                         if (checkedDays_1.Checked)
  509.                                         {
  510.                                             dayList.Add(Schedule.Day.Tuesday);
  511.                                         }
  512.                                         if (checkedDays_2.Checked)
  513.                                         {
  514.                                             dayList.Add(Schedule.Day.Wednesday);
  515.                                         }
  516.                                         if (checkedDays_3.Checked)
  517.                                         {
  518.                                             dayList.Add(Schedule.Day.Thursday);
  519.                                         }
  520.                                         if (checkedDays_4.Checked)
  521.                                         {
  522.                                             dayList.Add(Schedule.Day.Friday);
  523.                                         }
  524.                                         if (checkedDays_5.Checked)
  525.                                         {
  526.                                             dayList.Add(Schedule.Day.Saturday);
  527.                                         }
  528.                                         if (checkedDays_6.Checked)
  529.                                         {
  530.                                             dayList.Add(Schedule.Day.Sunday);
  531.                                         }
  532.                                         bool scheduleReturn = myschedule.ScheduleAnyTime(programme, quality, Schedule.DayType.SheduleSpecificDays, keepnumRecordings, dayList, Schedule.RecType.Season, prePad, postPad);
  533.                                     }
  534.                                 }
  535.  
  536.                                 // drop out after first season recording for the show
  537.                                 // (it really doesn't matter what we store here, but myRecording sounds usefull)
  538.                                 processedRecordings.Add(uniqueProgrammeKey, programme);
  539.                                 Channel chnl = myschedule.GetChannelByOID(programme.getChannelOID());
  540.                                 Recordings.Items.Add(programme.getOID().ToString() + "@" + chnl.channelName + " " + programme.getTitle().ToString() + " " + programme.getStartTime().ToLongDateString() + " " + programme.getStartTime().ToShortTimeString() + " - " + programme.getEndTime().ToShortTimeString());
  541.                             }
  542.                         }
  543.                     }
  544.                 }
  545.                 else
  546.                 {
  547.                     foreach (TreeNode node in TreeView1.CheckedNodes)
  548.                     {
  549.                         Programme programme = scheduleHelper.GetProgrammeByOID(System.Convert.ToInt32(node.Value));
  550.  
  551.                         if (Convert.ToDouble(extendMinutes.Text) != 0)
  552.                         {
  553.                             //Add the number of minutes that was entered to the end time of the recording to set the new end time
  554.                             DateTime newEndDate =
  555.                                 programme.getEndTime().AddMinutes(Convert.ToDouble(extendMinutes.Text));
  556.                             //Set the new end time for the recording
  557.                             programme.setEndTime(newEndDate);
  558.                         }
  559.  
  560.                         string uniqueProgrammeKey = programme.getChannelOID().ToString() + ":" + programme.getTitle();
  561.  
  562.                         if (!processedRecordings.Contains(uniqueProgrammeKey))
  563.                         {
  564.                             //Set the max number of recordings to keep for the show
  565.                             int keepnumRecordings = ReoccuringRecordingExtras.KEEP_ALL_FILES;
  566.                             if (keepRecordings.Text.ToString() != null)
  567.                             {
  568.                                 try
  569.                                 {
  570.                                     keepnumRecordings = Convert.ToInt32(keepRecordings.Text);
  571.                                 }
  572.                                 catch
  573.                                 {
  574.                                     keepnumRecordings = ReoccuringRecordingExtras.KEEP_ALL_FILES;
  575.                                 }
  576.                             }
  577.                             else
  578.                             {
  579.                                 keepnumRecordings = ReoccuringRecordingExtras.KEEP_ALL_FILES;
  580.                             }
  581.  
  582.                             Schedule myschedule = Global.Schedule;
  583.  
  584.                             if (radioTime.SelectedValue == "thisTime")
  585.                             {
  586.                                 // schedule season recording for any day and this time
  587.                                 if (radioDay.SelectedValue == "anyDay")
  588.                                 {
  589.                                     bool scheduleReturn = myschedule.ScheduleThisTime(programme, quality, Schedule.DayType.SheduleAnyDay, keepnumRecordings, Schedule.RecType.Season, prePad, postPad);
  590.                                 }
  591.                                 // schedule season recording for only this day and this time
  592.                                 else if (radioDay.SelectedValue == "thisDay")
  593.                                 {
  594.                                     bool scheduleReturn = myschedule.ScheduleThisTime(programme, quality, Schedule.DayType.SheduleThisDay, keepnumRecordings, Schedule.RecType.Season, prePad, postPad);
  595.                                 }
  596.                                 // schedule season recording for the selected days and this time
  597.                                 else
  598.                                 {
  599.                                     ArrayList dayList = new ArrayList();
  600.                                     // Iterate through the Items collection of the checkedDays 
  601.                                     // control and create the correct number for the season recording.
  602.                                     if (checkedDays_0.Checked)
  603.                                     {
  604.                                         dayList.Add(Schedule.Day.Monday);
  605.                                     }
  606.                                     if (checkedDays_1.Checked)
  607.                                     {
  608.                                         dayList.Add(Schedule.Day.Tuesday);
  609.                                     }
  610.                                     if (checkedDays_2.Checked)
  611.                                     {
  612.                                         dayList.Add(Schedule.Day.Wednesday);
  613.                                     }
  614.                                     if (checkedDays_3.Checked)
  615.                                     {
  616.                                         dayList.Add(Schedule.Day.Thursday);
  617.                                     }
  618.                                     if (checkedDays_4.Checked)
  619.                                     {
  620.                                         dayList.Add(Schedule.Day.Friday);
  621.                                     }
  622.                                     if (checkedDays_5.Checked)
  623.                                     {
  624.                                         dayList.Add(Schedule.Day.Saturday);
  625.                                     }
  626.                                     if (checkedDays_6.Checked)
  627.                                     {
  628.                                         dayList.Add(Schedule.Day.Sunday);
  629.                                     }
  630.                                     bool scheduleReturn = myschedule.ScheduleThisTime(programme, quality, Schedule.DayType.SheduleSpecificDays, keepnumRecordings, dayList, Schedule.RecType.Season, prePad, postPad);
  631.                                 }
  632.                             }
  633.                             else
  634.                             {
  635.                                 // schedule season recording for anyday anytime
  636.                                 if (radioDay.SelectedValue == "anyDay")
  637.                                 {
  638.                                     bool scheduleReturn = myschedule.ScheduleAnyTime(programme, quality, Schedule.DayType.SheduleAnyDay, keepnumRecordings, Schedule.RecType.Season, prePad, postPad);
  639.                                 }
  640.                                 // schedule season recording for only this day and thisany time
  641.                                 else if (radioDay.SelectedValue == "thisDay")
  642.                                 {
  643.                                     bool scheduleReturn = myschedule.ScheduleAnyTime(programme, quality, Schedule.DayType.SheduleThisDay, keepnumRecordings, Schedule.RecType.Season, prePad, postPad);
  644.                                 }
  645.                                 // schedule season recording for the selected days and this time
  646.                                 else
  647.                                 {
  648.                                     ArrayList dayList = new ArrayList();
  649.                                     // Iterate through the Items collection of the checkedDays 
  650.                                     // control and create the correct number for the season recording.
  651.                                     if (checkedDays_0.Checked)
  652.                                     {
  653.                                         dayList.Add(Schedule.Day.Monday);
  654.                                     }
  655.                                     if (checkedDays_1.Checked)
  656.                                     {
  657.                                         dayList.Add(Schedule.Day.Tuesday);
  658.                                     }
  659.                                     if (checkedDays_2.Checked)
  660.                                     {
  661.                                         dayList.Add(Schedule.Day.Wednesday);
  662.                                     }
  663.                                     if (checkedDays_3.Checked)
  664.                                     {
  665.                                         dayList.Add(Schedule.Day.Thursday);
  666.                                     }
  667.                                     if (checkedDays_4.Checked)
  668.                                     {
  669.                                         dayList.Add(Schedule.Day.Friday);
  670.                                     }
  671.                                     if (checkedDays_5.Checked)
  672.                                     {
  673.                                         dayList.Add(Schedule.Day.Saturday);
  674.                                     }
  675.                                     if (checkedDays_6.Checked)
  676.                                     {
  677.                                         dayList.Add(Schedule.Day.Sunday);
  678.                                     }
  679.                                     bool scheduleReturn = myschedule.ScheduleAnyTime(programme, quality, Schedule.DayType.SheduleSpecificDays, keepnumRecordings, dayList, Schedule.RecType.Season, prePad, postPad);
  680.                                 }
  681.                             }
  682.  
  683.                             // drop out after first season recording for the show
  684.                             // (it really doesn't matter what we store here, but myRecording sounds usefull)
  685.                             processedRecordings.Add(uniqueProgrammeKey, programme);
  686.                             Channel chnl = myschedule.GetChannelByOID(programme.getChannelOID());
  687.                             Recordings.Items.Add(programme.getOID().ToString() + "@" + chnl.channelName + " " + programme.getTitle().ToString() + " " + programme.getStartTime().ToLongDateString() + " " + programme.getStartTime().ToShortTimeString() + " - " + programme.getEndTime().ToShortTimeString());
  688.                         }
  689.                     }
  690.                 }
  691.             }
  692.         }
  693.  
  694.         private void SearchForEpisode(
  695.             bool checkTitle, bool checkDesc, bool checkSubtitle,
  696.             bool matchTitle, bool matchDesc, bool matchSubtitle, bool matchUniqueID,
  697.             String searchFor, bool caseSensitive, int minLength, int maxLength,
  698.             string[] channels, string[] selectedGenre, string startdate, string starttime, string enddate, string endtime)
  699.         {
  700.             Schedule scheduleHelper = Global.Schedule;
  701.  
  702.             ProgrammeDisplay2 displayProgramme = new ProgrammeDisplay2();
  703.             displayProgrammeSort = new ArrayList();
  704.             // build up a list of the recording we already know about
  705.             IDictionary knownRecordings = scheduleHelper.LoadKnownRecordings();
  706.  
  707.             Type pageType = Type.GetType("gbweb.SearchResults2");
  708.  
  709.             if (sr_searchResults.SelectedValue != "tree")
  710.             {
  711.                 createHeaderRow();
  712.             }
  713.  
  714.             if (searchFor != null)
  715.             {
  716.                 if (!caseSensitive)
  717.                 {
  718.                     searchFor = searchFor.ToUpper();
  719.                 }
  720.             }
  721.  
  722.             //Instantiate a new search engine
  723.             SearchEngine search = new SearchEngine();
  724.  
  725.             //Set the date variables for search processing
  726.             search.setSearchDateTime(startdate, starttime, enddate, endtime);
  727.  
  728.             //Call the method that will load an array with programmes that match the passed in search criteria
  729.             ArrayList ProgrammeArray = new ArrayList(search.SelectProgrammes(channels, selectedGenre, checkTitle, checkDesc, checkSubtitle, matchTitle, matchDesc, matchSubtitle, matchUniqueID, searchFor, caseSensitive, scheduleHelper, minLength, maxLength));
  730.  
  731.             //Release resources held by the search engine object
  732.             search.Dispose();
  733.  
  734.             //Verify the user has VLC installed by looking for it in the path that is set in the config
  735.             bool strmAllowed = File.Exists(Path.Combine(guideParams.strmVLCLoc, "vlc.exe"));
  736.  
  737.             CSSProgrammeTableLoad tableLoad = new CSSProgrammeTableLoad();
  738.  
  739.             foreach (Programme program in ProgrammeArray)
  740.             {
  741.                 if (sr_searchResults.SelectedValue == "table")
  742.                 {
  743.                     displayProgrammeSort.Add(program);
  744.                 }
  745.                 else
  746.                 {
  747.                     ScheduledRecording scheduledRecording = null;
  748.                     if (knownRecordings.Contains(program.getOID()))
  749.                         scheduledRecording = (ScheduledRecording) knownRecordings[program.getOID()];
  750.                     processTree(displayProgramme, program, scheduledRecording,
  751.                                 scheduleHelper.GetChannelByOID(program.getChannelOID()));
  752.                 }
  753.             }
  754.  
  755.             //Clear the arraylist of programmes to free up resources since we are done with it
  756.             ProgrammeArray.Clear();
  757.  
  758.             if (sr_searchResults.SelectedValue == "tree")
  759.             {
  760.                 //Resize the array of ProgrammeTreeItems so that is isn't hogging up space.
  761.                 Array.Resize(ref pgmTree, treeIdx);
  762.                 TreeView1.Nodes.Clear();
  763.                 //Fill the TreView Control with all the nodes in the correct format
  764.                 displayProgramme.FillProgrammeTree(TreeView1, pgmTree, srtOrder.SelectedValue);
  765.             }
  766.             else
  767.             {
  768.                 //Sort the matching programmes into the choosen sort order
  769.                 tableLoad.sortDisplay(sortOrders, displayProgrammeSort, false);
  770.  
  771.                 //Format the now sorted matching results into the CSS table format
  772.                 while (displayProgrammeSort.Count > 0)
  773.                 {
  774.                     ScheduledRecording scheduledRecording = null;
  775.                     Programme pgm = (Programme) displayProgrammeSort[0];
  776.                     if (knownRecordings.Contains(pgm.getOID())) scheduledRecording = (ScheduledRecording)knownRecordings[pgm.getOID()];
  777.                     tableLoad.processTable(pageType, sortOrders, Cache, Request, Server, displayProgramme, strmAllowed, pgm, scheduledRecording, false);
  778.                     displayProgrammeSort.RemoveAt(0);
  779.                 }
  780.                 //Call the finalize process for creating the TableView
  781.                 tableLoad.processTable(pageType, sortOrders, Cache, Request, Server, null, strmAllowed, null, null, true);
  782.                 
  783.                 //Fill the aspx page with the formatted results
  784.                 forcedScrollbar.InnerHtml = tableLoad.getForcedScrollBar();
  785.                 CONTENTS.InnerHtml = tableLoad.getContents();
  786.                 tableLoad.Dispose();
  787.                 CONTENTS.Attributes.Add("onscroll", "fScroll(this)");
  788.             }
  789.  
  790.             if (Recordings.Items.Count > 0)
  791.             {
  792.                 DropDownList FailedRecordings = new DropDownList();
  793.                 string [] programmeInfo;
  794.                 knownRecordings = scheduleHelper.LoadKnownRecordings();
  795.                 for (int i = 0; i < Recordings.Items.Count; i++)
  796.                 {
  797.                     programmeInfo = Recordings.Items[i].Value.Split('@');
  798.                     if (!knownRecordings.Contains(System.Convert.ToInt32(programmeInfo[0])))
  799.                     {
  800.                         FailedRecordings.Items.Add(programmeInfo[1]);
  801.                     }
  802.                 }
  803.                 if (FailedRecordings.Items.Count > 0)
  804.                 {
  805.                     Recordings.Items.Clear();
  806.                     ListItem [] failures = new ListItem[FailedRecordings.Items.Count];
  807.                     FailedRecordings.Items.CopyTo(failures,0);
  808.                     Recordings.Items.AddRange(failures);
  809.                     RecordMessage.Text = "Recordings That Failed to Schedule:";
  810.                     ERROR_MESSAGE.Visible = true;
  811.                     Recordings.Visible = true;
  812.                     RecordMessage.Visible = true;
  813.                 }
  814.                 else
  815.                 {
  816.                     Recordings.Items.Clear();
  817.                     ERROR_MESSAGE.Visible = false;
  818.                     Recordings.Visible = false;
  819.                     RecordMessage.Visible = false;
  820.                 }
  821.             }
  822.  
  823.             displayProgramme.Dispose();
  824.         }
  825.  
  826.         #region Page Load code for the TreeView - ProcessTree
  827.         //This is the main driver routine for loading the TableView
  828.         private void processTree(ProgrammeDisplay2 displayProgramme, Programme programme, ScheduledRecording scheduledRecording, Channel chnl)
  829.         {
  830.             //Create a ProgrammeTreeItem to be loaded with the correct display information for the program
  831.             ProgramTreeItem treeItem = new ProgramTreeItem();
  832.             displayProgramme.FillProgrammeTreeArrayItem(treeItem, Server, programme, scheduledRecording, true, chnl);
  833.             //Add the loaded ProgrammeTreeITem to the Array
  834.             pgmTree[treeIdx] = treeItem;
  835.             treeIdx = treeIdx + 1;
  836.         }
  837.         #endregion
  838.  
  839.         private void createHeaderRow() {
  840.             TableRow headerRow = new TableRow();
  841.  
  842.             TableCell col1 = new TableCell();
  843.             col1.CssClass = "header";
  844.             col1.Text = "<nobr><input type=\"checkbox\" class=\"selectall\" onclick=\"SelectAllCheckboxes(this);\"><b>Select</b></nobr>";
  845.             headerRow.Cells.Add(col1);
  846.  
  847.             TableCell col3 = new TableCell();
  848.             col3.CssClass = "header";
  849.             col3.Text = "Channel";
  850.             headerRow.Cells.Add(col3);
  851.  
  852.             TableCell col3a = new TableCell();
  853.             col3a.CssClass = "header";
  854.             col3a.Text = "Show";
  855.             headerRow.Cells.Add(col3a);
  856.  
  857.             TableCell col4 = new TableCell();
  858.             col4.CssClass = "header";
  859.             col4.Text = "Air Date";
  860.             headerRow.Cells.Add(col4);
  861.  
  862.         }
  863.  
  864.         #region Web Form Designer generated code
  865.         override protected void OnInit(EventArgs e)
  866.         {
  867.             //
  868.             // CODEGEN: This call is required by the ASP.NET Web Form Designer.
  869.             //
  870.             InitializeComponent();
  871.             base.OnInit(e);
  872.         }
  873.  
  874.         /// <summary>
  875.         /// Required method for Designer support - do not modify
  876.         /// the contents of this method with the code editor.
  877.         /// </summary>
  878.         private void InitializeComponent()
  879.         {
  880.             this.PreRender += new System.EventHandler(this.SearchResults_PreRender);
  881.         }
  882.         #endregion
  883.  
  884. }
  885. }
  886.  
  887.